﻿<UserControl x:Class="ViewIndicateurFormula"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <Style x:Key="textBoxInError" TargetType="TextBox">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"
                Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!--<ComboBox IsTextSearchEnabled="True"  Background="White" Margin="5"  >
            
        </ComboBox>-->
        <DockPanel Margin="5">
            <TextBlock Text="Nom      :  " VerticalAlignment="Center"  />
            <TextBox Style="{StaticResource textBoxInError}"  Name="NameTextBox"  Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Grid.Row="0"   />

        </DockPanel>
        <DockPanel    Grid.Row="1"  Margin="5">
            <TextBlock DockPanel.Dock="Left" Text="Formule :  " VerticalAlignment="Center"  />
            <Button Command="{Binding ValidateFormulaCommand}" Padding="1" Margin="2" Content="Valider" DockPanel.Dock="Right" />
            <TextBox DockPanel.Dock="Right"  Style="{StaticResource textBoxInError}" Name="FormulaTextBox" Text="{Binding Formula, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" AcceptsReturn="False" AcceptsTab="True" TextWrapping="Wrap"  />
        </DockPanel>
        <Popup Name="FormulaPopup" Grid.Row="1" PlacementTarget="{Binding ElementName=FormulaTextBox}" Width="{Binding ElementName=FormulaTextBox, Path=ActualWidth}" Placement="Bottom" >
            <ListBox  Height="100"/>
        </Popup>
        <UniformGrid Margin="5" Grid.Row="2" Columns="4">
            <ListBox Focusable="False" Margin="5" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Tables}" DisplayMemberPath="TableName">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" >
                        <!--<Setter Property="Focusable" Value="false" />-->
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
            <ListBox Focusable="False" Margin="5" HorizontalContentAlignment="Stretch"  IsSynchronizedWithCurrentItem="True"  ItemsSource="{Binding Tables/Columns}" DisplayMemberPath="ColumnName">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" >
                        <EventSetter Event="MouseDoubleClick" Handler="ColumnsListBoxItemMouseDoubleClick" />
                        <!--<Setter Property="Focusable" Value="false" />-->
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
            <UniformGrid Rows="2">
                <ListBox Focusable="False" Name="ParentRelationsListBox" Margin="5"  IsSynchronizedWithCurrentItem="True"  ItemsSource="{Binding Tables/ParentRelations}" DisplayMemberPath="RelationName">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem" >
                            <!--<Setter Property="Focusable" Value="false" />-->
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
                <ListBox Visibility="Collapsed" Focusable="False" Name="ChildRelationsListBox" Margin="5"  IsSynchronizedWithCurrentItem="True"  ItemsSource="{Binding Tables/ChildRelations}" DisplayMemberPath="RelationName">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem" >
                            <!--<Setter Property="Focusable" Value="false" />-->
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
            </UniformGrid>
            <UniformGrid Rows="2">

                <ListBox Focusable="False" Margin="5"  IsSynchronizedWithCurrentItem="True"  ItemsSource="{Binding  Tables/ParentRelations/ParentTable.Columns}" DisplayMemberPath="ColumnName">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem" >
                            <EventSetter Event="MouseDoubleClick" Handler="ParentTableColumnsListBoxItemMouseDoubleClick" />
                            <!--<Setter Property="Focusable" Value="false" />-->
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
                <ListBox Visibility="Collapsed" Focusable="False" Margin="5"  IsSynchronizedWithCurrentItem="True"  ItemsSource="{Binding Tables/ChildRelations/ChildTable.Columns}" DisplayMemberPath="ColumnName">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem" >
                            <EventSetter Event="MouseDoubleClick" Handler="ChildTableColumnsListBoxItemMouseDoubleClick" />
                            <!--<Setter Property="Focusable" Value="false" />-->
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
            </UniformGrid>
        </UniformGrid>
    </Grid>
</UserControl>
